package cn.wolfcode.p2p.bussness.service;

import cn.wolfcode.p2p.base.query.QueryObject;
import cn.wolfcode.p2p.bussness.domain.ExpAccount;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.time.DateUtils;

import java.math.BigDecimal;
import java.util.Date;

public interface IExpAccountService {
    int save(ExpAccount expAccount);

    int update(ExpAccount expAccount);

    ExpAccount get(Long id);

    PageInfo queryPage(QueryObject qo);

    /**
     * 有效期
     */
    class LastTime{
        private int amount;
        private LastTimeUnit unit;

        public LastTime(int amount, LastTimeUnit unit) {
            this.amount = amount;
            this.unit = unit;
        }

        public Date getReturnDate(Date date){
            switch (this.unit){
                case DAY:
                    return DateUtils.addDays(date,this.amount);
                case  MONTH:
                    return  DateUtils.addMonths(date,amount);
                case YEAR:
                    return DateUtils.addYears(date,amount);
                default:
                    return date;
            }
        }
    }

    /**
     * 持续时间单位
     * 天 月 年
     */
    enum LastTimeUnit{
        DAY, MONTH, YEAR
    }

    /**
     * 发放体验金
     * @param id            体验金账户id
     * @param lastTime      有效期
     * @param expMoney      发放金额
     * @param expMoneyType  发放类型
     */
    void grantExpMoney(Long id, LastTime lastTime, BigDecimal expMoney, int expMoneyType);
}
